//
//  DepartmentModel.m
//  AddressBook
//
//  Created by ladystyle100 on 2017/8/31.
//  Copyright © 2017年 mac. All rights reserved.
//

#import "DepartmentModel.h"
#import "NSObject+XQArchiverData.h"

@implementation DepartmentModel

- (instancetype)initWithCoder:(NSCoder *)aDecoder {
    self = [super init];
    if (self) {
        [self decoder:aDecoder];
    }
    return self;
}

- (void)encodeWithCoder:(NSCoder *)aCoder {
    [self encoder:aCoder];
}

+ (NSArray <DepartmentModel *> *)modelArrWithInfo:(NSArray *)info section:(NSArray *)section {
    NSMutableArray *returnArr = [NSMutableArray array];
    if (!info || !section) {
        return returnArr;
    }
    
    NSMutableArray <PeopleModel *> *pModelArr = [NSMutableArray array];
    
    // 把所有人转成model
    for (NSDictionary *infoDic in info) {
        PeopleModel *model = [PeopleModel modelWithDic:infoDic];
        if (model) {
            [pModelArr addObject:model];
        }
    }
    
    
    for (NSDictionary *sectionDic in section) {
        NSString *section_name = sectionDic[@"section_name"];
        NSPredicate *predicate = [NSPredicate predicateWithFormat:@"_section_name CONTAINS[cd] %@", section_name];
        
        NSArray <PeopleModel *> *filterArr = [pModelArr filteredArrayUsingPredicate:predicate];
        if (filterArr.count == 0) {
            continue;
        }
        
        DepartmentModel *model = [DepartmentModel new];
        model.section_name = filterArr.firstObject.section_name;
        model.info = filterArr;
        
        [returnArr addObject:model];
        
        NSLog(@"section_name = %@, info = %@", model.section_name, model.info);
    }
    
    return returnArr;
}

- (void)setValue:(id)value forUndefinedKey:(NSString *)key {
    
}


@end












